package com.lijin.study.java.thread.concurr;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyExecutor extends Thread {
	private int index;
	public MyExecutor(int i){
		this.index=i;
	}
	
	public void run(){
		try{
			System.out.println("["+this.index+"] start...." + System.currentTimeMillis());
			int r = (int)(Math.random()*10000);
			System.out.println(this.index + "-" + r);
			Thread.sleep(r);
			System.out.println("["+this.index+"] end...." + System.currentTimeMillis());
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public static void main(String args[]){
		ExecutorService service=Executors.newFixedThreadPool(4);
		for(int i=0;i<10;i++){
			service.execute(new MyExecutor(i));
		}
		System.out.println("submit finish..." + System.currentTimeMillis());
		service.shutdown();
	}
}